import QtQuick 2.12
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import QtQuick.Extras 1.4
import QtGraphicalEffects 1.0
import QtQuick.LocalStorage 2.0
import "storage.js" as Storage

Rectangle {
    id: main_screen
    width: 1024
    height: 768
    color: "#295282"
    property real minSize:  Math.min(width/1024, height/768)

    Timer{
        interval: 100
        repeat: true
        triggeredOnStart: false
        running: true
        property int mdate: 0
        onTriggered: {
            if($sqlMcRecorder.qml_getResetFlagConstantRecorder())
                qmlSL_modbusDataStoreFinishCallback()
        }
    }

    function qmlSL_modbusDataStoreFinishCallback()
    {
        var tWhich = Storage.readWhichChannelRunning()
        pm_ugText.num = $sqlMcRecorder.qml_getRecordVal_bystr_toint16(tWhich+"机端电压")/100
        pm_igText.num = $sqlMcRecorder.qml_getRecordVal_bystr_toint16(tWhich+"机端电流")/100
        pm_ilText.num = $sqlMcRecorder.qml_getRecordVal_bystr_toint16(tWhich+"励磁电流")/100
        pm_pText.num = $sqlMcRecorder.qml_getRecordVal_bystr_toint16(tWhich+"有功功率")/100
        pm_qText.num = $sqlMcRecorder.qml_getRecordVal_bystr_toint16(tWhich+"无功功率")/100


        pagehome.qmlSN_sqlWriteFinish()
        page1.qmlSN_sqlWriteFinish()
        page2.qmlSN_sqlWriteFinish()
        page3.qmlSN_sqlWriteFinish()
        page5.qmlSN_sqlWriteFinish()
        page6.qmlSN_sqlWriteFinish()
        page7.qmlSN_sqlWriteFinish()
        page8.qmlSN_sqlWriteFinish()
        page9.qmlSN_sqlWriteFinish()
        page10.qmlSN_sqlWriteFinish()
        page4.qmlSN_sqlWriteFinish()
    }

    function qmlSL_sqlAlarmWriteFinishCallback(var_now, var_history)
    {
        if(var_history.length>0) {
            page4.qmlSN_sqlAlarmWriteFinish(var_now,var_history)
            pagehome.qmlSN_sqlAlarmWriteFinish(var_now,var_history)
        }
    }

    Image {
        id: image
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.verticalCenter: parent.verticalCenter
        property real minSize:  Math.min(parent.width/1024, parent.height/768)
        sourceSize.height: 768 * minSize
        sourceSize.width: 1024 * minSize
        source: "../picture/p_background/EXC-pm-ext2.png"
        fillMode: Image.PreserveAspectFit

        MouseArea {
            height:  80* parent.minSize
            anchors.right: parent.right
            anchors.left: parent.left
            anchors.top: parent.top
            onDoubleClicked: main_svshow.currentIndex=1
        }
        Text {
            id: pm_ugText
            x: 98* parent.minSize
            y: 2* parent.minSize
            color: "#dddddd"
            text: Number(num).toFixed(2)+"%"
            font.bold: true
            font.family: "Tahoma"
            property real num: 0
            font.pixelSize: 20* parent.minSize
        }

        Text {
            id: pm_igText
            x: 290* parent.minSize
            y: 2* parent.minSize
            color: "#dddddd"
            text: Number(num).toFixed(2)+"%"
            font.bold: true
            font.family: "Tahoma"
            property real num: 0
            font.pixelSize: 20* parent.minSize
        }

        Text {
            id: pm_ilText
            x: 498* parent.minSize
            y: 2* parent.minSize
            color: "#dddddd"
            text: Number(num).toFixed(2)+"%"
            font.bold: true
            font.family: "Tahoma"
            property real num: 0
            font.pixelSize: 20* parent.minSize
        }

        Text {
            id: pm_pText
            x: 698* parent.minSize
            y: 2* parent.minSize
            color: "#dddddd"
            text: Number(num).toFixed(2)+"%"
            font.bold: true
            font.family: "Tahoma"
            property real num: 0
            font.pixelSize: 20* parent.minSize
        }

        Text {
            id: pm_qText
            x: 909* parent.minSize
            y: 2* parent.minSize
            color: "#dddddd"
            text: Number(num).toFixed(2)+"%"
            font.bold: true
            font.family: "Tahoma"
            property real num: 0
            font.pixelSize: 20* parent.minSize
        }

        Image {
            x: parent.width/1024*42
            anchors.bottom: parent.bottom
            anchors.bottomMargin: parent.height/768*4
            scale:minSize
            width: 120 * parent.minSize
            source: "../picture/p_background/homepage.png"
            fillMode: Image.PreserveAspectFit
            MouseArea {
                anchors.fill: parent
                onPressed: parent.scale=0.95*minSize
                onReleased: {parent.scale=1*minSize;main_svshow.currentIndex=0}
            }
        }
        Image {
            x: parent.width/1024*249
            anchors.bottom: parent.bottom
            anchors.bottomMargin: parent.height/768*4
            scale:minSize
            width: 120 * parent.minSize
            source: "../picture/p_background/Promotion.png"
            fillMode: Image.PreserveAspectFit
            MouseArea {
                anchors.fill: parent
                onPressed: parent.scale=0.95*minSize
                onReleased: {parent.scale=1*minSize;main_svshow.currentIndex=3}
            }
        }
        Image {
            x: parent.width/1024*456
            anchors.bottom: parent.bottom
            anchors.bottomMargin: parent.height/768*4
            scale:minSize
            width: 120 * parent.minSize
            source: "../picture/p_background/moniter.png"
            fillMode: Image.PreserveAspectFit
            MouseArea {
                anchors.fill: parent
                onPressed: parent.scale=0.95*minSize
                onReleased: parent.scale=1*minSize
                onClicked: main_svshow.currentIndex=6
                onDoubleClicked: main_svshow.currentIndex=7
            }
        }
        Image {
            x: parent.width/1024*661
            anchors.bottom: parent.bottom
            anchors.bottomMargin: parent.height/768*4
            scale:minSize
            width: 120 * parent.minSize
            source: "../picture/p_background/testing.png"
            fillMode: Image.PreserveAspectFit
            MouseArea {
                anchors.fill: parent
                onPressed: parent.scale=0.95*minSize
                onReleased: {parent.scale=1*minSize;main_svshow.currentIndex=9;page9.qmlSN_returnMainPage()}
            }
        }
        Image {
            x: parent.width/1024*864
            anchors.bottom: parent.bottom
            anchors.bottomMargin: parent.height/768*4
            scale:minSize
            width: 120 * parent.minSize
            source: "../picture/p_background/setting.png"
            fillMode: Image.PreserveAspectFit
            MouseArea {
                anchors.fill: parent
                onPressed: parent.scale=0.95*minSize
                onReleased: {parent.scale=1*minSize;main_svshow.currentIndex=10;page10.qmlSN_returnMainPage()}
            }
        }
    }

    SwipeView{
        id: main_svshow
        property real minSize:  main_screen.minSize
        height: 610*minSize
        width: 1024*minSize
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.verticalCenter: parent.verticalCenter
        padding: 0
        currentIndex: 0
        clip: true
        orientation: Qt.Vertical
        interactive: false

        Item {
            Page_00Home{
                id:pagehome
                width: parent.width
                height: parent.height
            }
        }
        Page_01First {id: page1}
        Page_02SystemSimple {id: page2}
        Page_03Promotion { id: page3}
        Page_04AlarmMsg { id: page4 }
        Page_05LimiterStatu{ id: page5 }
        Page_06IOMonitor{ id: page6;onQmlSN_switchAnalog: {main_svshow.currentIndex = 7}}
        Page_07AnalogMonitor { id: page7}
        Page_08OperatorModel { id: page8}
        Page_09ExperimentOperation {
            id: page9
            onQmlSN_toP3promotion: main_svshow.currentIndex=3
            onQmlSN_changePage10Index: {main_svshow.currentIndex=10; page10.changeToPage(var1)}
        }
        Page_10FactorSetting { id: page10}

    }


}

/*##^##
Designer {
    D{i:0;formeditorZoom:0.75}
}
##^##*/
